package com.leyou.trade.web;

import com.leyou.trade.dto.PayResultDTO;
import com.leyou.trade.service.PayService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/pay")
public class PayController {
    private final PayService payService;

    public PayController(PayService payService){

        this.payService = payService;
    }

    /**
     * 获取支付链接
     * @param id
     * @return
     */
    @GetMapping("/url/{id}")
    public ResponseEntity<String> getPayUrl(@PathVariable("id")Long id){

        return ResponseEntity.ok(this.payService.getPayUrl(id));
    }

    /**
     * 处理微信回调通知
     * @param resultMap
     * @return
     */
    @PostMapping("/wx/notify")
    public ResponseEntity<PayResultDTO> handleWxNotify(
            @RequestBody Map<String,String> resultMap){

        this.payService.handleWxNotify(resultMap);


        return ResponseEntity.ok(new PayResultDTO());
    }

}
